{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sympy import diff, latex, init_printing\n",
      "from sympy.abc import t, x\n",
      "from IPython.display import display\n",
      "\n",
      "init_printing()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 15
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "xf = x(t)\n",
      "dxf = diff(xf, t)\n",
      "ddxf = diff(dxf, t)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 17
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "map(display, (xf, dxf, ddxf))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "latex": [
        "$$x{\\left (t \\right )}$$"
       ],
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAACEAAAAVBAMAAAA6IZrnAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\n75nQ6/gxAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA70lEQVQYGXWQvUoDQRSFv4nJ/oxRl7UWFoW0\n+gjbiIUIARs7Fy3sJIWlRRCxsBrfIG+gqGCZfQMr+23tYmHvmV2ym8YL95w75945cxn4N4YT37pd\n6R/X9VrZSU9g7sG1Sq8Au4BRq2zksKmBnVY5UxUVEM8g3TscZVzD6fwtI6gwRXgXOT4086wMHUES\n/NicR52+lXaKIX5R9aV8UA71HluZQIr5XSqfJYm/NViIB1Nssk8v8c6Bs6V3Pp/NOYJLLXiQCiq2\nd9OrCWjD/qsM47HM6ojyhk8aEoaVQHHRkMf3ujSuU5ofW887pS97uIE/5JUqG3wBkdgAAAAASUVO\nRK5CYII=\n",
       "text": [
        "x(t)"
       ]
      },
      {
       "latex": [
        "$$\\frac{d}{d t} x{\\left (t \\right )}$$"
       ],
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAADYAAAArBAMAAADBI2arAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMARLvvmVQQid3NIqt2\nMmaorGxOAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABlklEQVQ4EXWTvUvDUBTFT9I2aUOtBRcHoQUn\nnTo7SAcXcekkIkizqVM7iCgouom6qOgeXAURF0EqxKVdKvgX2A4OukgR2knRm3f77LN5uZDec+8v\nX+XkAEEZk0XRtT+jJe1aLHNuNNuKRjiPYs7dUzeKjXlmL4JZs4ifRLB4D8lqBIvlUclGsEoVZbh6\nWClhKuHpWcrPHNt6BKu2e/WospdgyDyrK6mdvFAPclZ7ygXWPKTUndQNEmUgrfvPM8TmAasgTx50\nY5/0AR0Xgx2d2byf2IFdhHH7WQM2VLaKN/8QZhtIdGj/rrJN7LnLSJbAviypzMUZjbEs2JcWfmQF\nt/nqM+FLS70OI9+wxD1z1DGussV0B3XxLttY+f8uRtfsOG3YN8CC5QNzynVWrd74oO9/H7hs0v5U\nYVIesXAKQR9Kyisz2xedkkKmyDJZrvNMSSFTZPW9neaZkkKm/NV1oDIez5SUwJRwBUlhU8JMJEWY\nEmKcFH1YOCn6sHBS9GHhpAhTQs/jpAhTQoyTIkwJMU6KMGWY/QJU/GZUMVfi7QAAAABJRU5ErkJg\ngg==\n",
       "text": [
        "d       \n",
        "\u2500\u2500(x(t))\n",
        "dt      "
       ]
      },
      {
       "latex": [
        "$$\\frac{d^{2}}{d t^{2}}  x{\\left (t \\right )}$$"
       ],
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAD8AAAAvBAMAAACmpw93AAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMARLvvmVQQid3NIqt2\nMmaorGxOAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACD0lEQVQ4EX1TQUsbQRh9a9zdJJoY6MFCKREq\nhVpR/ANt6EGQXkLBY8lCL0IDycGDrVq8iBA95GB7ntpjoS29FMHD9uShirl6MgdPgmCF5tDL+mYn\n223Wnflg5vvmey+zkzfzgH64z+ajMj2/xX46EHVbOBNRnZrn8LWUCsTNmhfXycp6UAF2kt3/12NV\nuOToo+zhXI8SWYHVtDoGyi5OF194OkL+x/EfPA0CHY47YqinBQk4TzDcNhGGe8g2TYTMBBpGlRtN\n1OAZtmhU8cgWBkLOL267BhzOwfrnn0lCoSs7l8l2vN4LyxG9+h+oTwvQ6jNKYewr4DDec7DKCITy\nvhpsx6u7LKW8uWrc61f1Xx8PfSwD92Yf+ynPzGkWd7JtzJBe4yi2kzu4ntuzBTbZX+CwNxAMBBzk\nJgjMcWxxFPhPkjHms0OC85s5jXDW4dXyE9YVs7VBVhTLkx4/6p1g1JOHdNt2Z+CQrhjhkcvVWXwB\nVqnTtzqnSvRz6iIKf4HXR/V3XYBC5ad9ClWShNCZyJTy8lgqskLlTyrRmUvs2PHjL1YUsqYSnSll\ny/pqKeepsHT6Qq4o2XgB/0I9mCGhGruhbNG2YS/flelCTtKZ1vfrA4zjvlzfitCZfD2F94sPb4Fs\nKGfSnJkgSLkZahU602BO5UyDOZUzy3wImlDOfIOXGhzKmc8dX0dQztw70uE38pmBvUrwZWcAAAAA\nSUVORK5CYII=\n",
       "text": [
        "  2      \n",
        " d       \n",
        "\u2500\u2500\u2500(x(t))\n",
        "  2      \n",
        "dt       "
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 19,
       "text": [
        "[None, None, None]"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "expr = xf * xf\n",
      "dexpr = diff(expr, t)\n",
      "ddexpr = diff(dexpr, t)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 20
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "display(expr)\n",
      "display(dexpr)\n",
      "display(ddexpr)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "latex": [
        "$$x^{2}{\\left (t \\right )}$$"
       ],
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAACsAAAAZBAMAAABawcpVAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarIkSJZt3NVLsy\nme8Q6PJIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABLElEQVQoFW2RsUvDQBTGv9j0kl5jDHGXoNDV\n/glZxE0CgpNgcXEqODgqFBHnzE6ZXaw6S7M5mtXdPyAFnev3LiFNIQ/u3fd+793duzugsulHUKv2\npOJe2o5r7cbebwf2E/uvAwN62YndiPjTpG5bBVNqe25AL2+4U1AO2KT1AKybOsM5MGJKl9VsFnhP\nz6/AD/U2S/cMo/NXqxL9GZU74WYZEB4cjSLGgCqA08V7JMKaOPdudcbwmrkXDieFCtRSx9Rcn9F9\nc+gZLAzmVGJ+QvfI4ZV0OxGdmGBLnsbgrxyBwbJJv2TAlnRwiK0Ky5Eq1bkceZEtcGyKoca8zTik\nK7C7H16xSkyuY79FvE4iYWN8JWMnDTHirg4vN/EwNrGVbuL6G+rsOle1dAP8AwEpNlmWoFIQAAAA\nAElFTkSuQmCC\n",
       "text": [
        " 2   \n",
        "x (t)"
       ]
      },
      {
       "latex": [
        "$$2 x{\\left (t \\right )} \\frac{d}{d t} x{\\left (t \\right )}$$"
       ],
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAGUAAAArBAMAAACTAFvgAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACY0lEQVRIDZXTz2sTQRQH8G+ajLvNj7ogFPQg\nQcGLBwOCIBYa/wHdU6UiJCIiSMAgiqABA4IgFEr1pAeJFz14MOhVaA6WeOghFT0bxVMPsqChIob4\nZnZmdpvMDukj2Zl5n/fYZXcGsMWDxzZNsGFC3pJ2BxZMIKeVAJZ0rmhBI803zveMkJx017DoJ7NR\nlvs4bgRL8oSPVxY20hOwP0ZITrIdFAKW7CZhQ6TbWyax5N5ju1q3uKRzYvwRrpa6Z2tNCWIQyjF1\n5GRZQaokZvt0QoEYQ+W4BEe/nRx9QvYCaO+qVQtSiVeBpyrbpUkhAPg4GZSV+Ay4UZYFazTO0E2W\nJxsoQypx3dc9boskWwdyPUMT1wjf+Gzz8koDThF4uHiqIyaxLq0Ruju4gO3Oa6T7VPiV/nP0fLGI\nVGO2hNu4728hyx+Jb+VCK9aBmGo8Cvh4R1WzTbrwrZwJ6BJFpArzVa7/6M97xFbmPSMVvF+qxk9I\necj8BhPP5gZ0U/ECqVSFUoWZIvLel3yADfEOnHahPP4OtCo8dOfmdXeYDlJ9OFX6atVLdCmqO/Ax\nUoXro9FfVtvo/iRs0ZZd6NA3bVKpjkgNCNqeIg7q+vhE6hh+lyWNcHRPF+M9UiUqSXtixtoysb+H\ni2GKJ0LVKGvkmZOtwKovttIu1SizOCwm39TybriV1FKoRpUdG9+GW2ksa1mmrn0Yuld+1SwlE/TI\nSw/EYZ6QxAR7zk8yP8zTx8yAn2R+mKeP2RIqTf7bQ1Tq9G38VToi00elhzMF7x4+T9+CXGfupYNj\nrLOHHla7Nf8RBzYNLf8B89mwq7VChz8AAAAASUVORK5CYII=\n",
       "text": [
        "       d       \n",
        "2\u22c5x(t)\u22c5\u2500\u2500(x(t))\n",
        "       dt      "
       ]
      },
      {
       "latex": [
        "$$2 x{\\left (t \\right )} \\frac{d^{2}}{d t^{2}}  x{\\left (t \\right )} + 2 \\left(\\frac{d}{d t} x{\\left (t \\right )}\\right)^{2}$$"
       ],
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAPkAAAA4BAMAAADN1UOyAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIpm7MhCriUTv3c12\nVGZoascqAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAF7UlEQVRYCcVYXWgcVRQ+m81kZ3ezm1WhoA+6\nNFgQHxJ/oSh09VUw40ukKmRFi6CBrEEp2EAWFEURk1qQKmi3Cgax4KIgQixdwRofCk39eahYEqtP\nLZgtNlSkcT3n3J+5s3NnZhsiuZC553zn+87Jzty9Z+4CbNfIDN+6XaWx7vPw3DZWPwpjpe0rfxhu\nqSdWn77TS+RskrCSmDlTGmhuMnmi7FgiI1fqv5RIChIy9aDf5Y0rP1NWVuScraf+jgzaA9N2WKGu\nupfnFRI1v/w2QGE9KmrHM1WJk9g2LgrQrbkVW9jANgByLcPvwTyr1xKKbSNdY/Shcz9qpo0G4OLn\nTriR3ULnsEJIbBvO+4we6XRsUQPLNKBYNvwezLTmo9g+ztrhEJovw2vwSgiOA/wvMYrtIyduvT2o\n0R0zY8v9x8/do4FejA8licQR/EIv32H3IOzxsp1OOyKJFS7KzCy2MhBU/2FUnPC9q3B7XNway40K\nOFa85lm1AXDEg4UA0IszVhesWPFEKznVIXCudZsDuE3mjRXnm4nVnStQaDuJtC7CO8KPFw8mLztn\nA9LNM13Jk9z+f2X1WHHqalIegK/hQrWWTAsw9KeKFx8KiJTzMBnFinDHlx6YrAvTvwYYPqys9Ly0\nQmIW/iGjuxU/tfOuirZH2Xpa+eE5FcG4fvhuJmdFPEo4UBGR2ZJkjENGr+y8B/BYCfJhsUIiGE4V\nZuvEmS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Bbq5O\nOfDFGpsl90sjpTaHWtq0G+Igxn3JTohAc2UKTNTwu+5xv7Tx1jwbamDiFMd9yUCTzSIv+olluK9Q\n4n5pk3xpAwMYH8S4LwXgRId/pMu3ih9nRL+0CNxLFjAI8UGM+1IQT/K4KTiTL+z4HrhfWvjpsgXc\nGijylyo/vf97oo9tkZXiM01cMv/3xDjWJmOW1/Fgpv/xxuPLUzVYLOT9HkK2EpiMT+ZG7b/xsl6j\nffVY5rix1fwHBjatHoE4KbUAAAAASUVORK5CYII=\n",
       "text": [
        "         2                     2\n",
        "        d            \u239bd       \u239e \n",
        "2\u22c5x(t)\u22c5\u2500\u2500\u2500(x(t)) + 2\u22c5\u239c\u2500\u2500(x(t))\u239f \n",
        "         2           \u239ddt      \u23a0 \n",
        "       dt                       "
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x0 = 2\n",
      "xdot0 = 5\n",
      "xddot0 = 1\n",
      "args = [(xf, x0), (dxf, xdot0), (ddxf, xddot0)]\n",
      "\n",
      "print expr.subs(args)\n",
      "print dexpr.subs(args)\n",
      "print ddexpr.subs(args)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "4\n",
        "4*Derivative(2, t)\n",
        "2*Derivative(2, t)**2 + 4*Derivative(2, t, t)\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}